package org.zoomdev.zoom;

import com.alibaba.fastjson2.JSONWriter;
import org.zoomdev.zoom.security.Sensitive;

public class UserWriter implements BeanWriter<User> {

    private final Sensitive<String>[] sensitives;

    UserWriter(Sensitive<String>[] sensitives) {
        this.sensitives = sensitives;
    }

    @Override
    public void write(JSONWriter jsonWriter, User user) {
        jsonWriter.startObject();


        jsonWriter.writeRaw("name");
        jsonWriter.writeColon();
        jsonWriter.writeString(sensitives[0].toSensitiveString(user.getName()));

        jsonWriter.writeComma();

        jsonWriter.writeRaw("adult");
        jsonWriter.writeColon();
        jsonWriter.writeBool(user.isAdult());

        jsonWriter.writeComma();

        jsonWriter.writeRaw("idCard");
        jsonWriter.writeColon();
        jsonWriter.writeString(sensitives[1].toSensitiveString(user.getIdCard()));

        jsonWriter.writeComma();

        jsonWriter.writeRaw("bankCard");
        jsonWriter.writeColon();
        jsonWriter.writeString(sensitives[2].toSensitiveString(user.getBankCard()));


        jsonWriter.endObject();
    }
}
